/**
 * 
 */
package cn.biplam.front.template.control.pop;

import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.common.wrapper.UserInfo;
import cn.biplam.front.html.HtmlDiv;
import cn.biplam.front.html.base.Html;
import cn.biplam.front.html.base.HtmlWindow;
import cn.biplam.front.html.base.Const.Window_Event;
import cn.biplam.front.template.Template;
import cn.biplam.front.template.control.pop.PopLevel.PopView_Layer;

/**
 * 信息提示框
 */
public class PopView implements Template{
	
	private String cssID="pb";
	private FramePopView frame;
	private String ID;
	private UserInfo mUser;
	private HtmlWindow prompt;

	private String sHomeUrl;
	
	/**
	 * 构造方法
	 * @param ID		Confirm窗口绑定对象ID(外部Div)
	 * @param sHomeUrl	主页Url
	 * @param sTitle	标题
	 * @throws ErrorMessage 
	 */
	public PopView(String ID,String sHomeUrl,UserInfo mUser) throws ErrorMessage{
		this.ID=ID;
		this.sHomeUrl=sHomeUrl;
		this.mUser=mUser;
		this._init();
	}
	
	/**
	 * 
	 * @param sTitle
	 * @throws ErrorMessage
	 */
	private void _init() throws ErrorMessage{
		frame=new FramePopView(ID+"f",sHomeUrl,mUser);
	}
	
	/**
	 * 绑定Frame的确认按钮事件
	 * @param sScript	事件执行的js脚本
	 * @throws ErrorMessage
	 */
	public void bindSubmit(String sScript) throws ErrorMessage{
		this.frame.bindSubmit(sScript);
	}
	
	/**
	 * 返回设置好的HtmlWindow对象
	 * @return
	 * @throws ErrorMessage 
	 */
	public HtmlWindow get() throws ErrorMessage{
		prompt=new HtmlDiv(ID,"pp");
		prompt.setZIndex(PopView_Layer.Back.toString());
		prompt.put(new HtmlDiv(this.ID+"b",cssID));
		frame.setLayerIndex(PopView_Layer.Frame);
		
		/**装入设置好的Frame*/
		prompt.put(frame.get());
		/**绑定关闭脚本*/
		this.bindBodyClickClose(prompt);
		return this.prompt;
	}
	
	/**
	 * 向Frame正文区域放入Html对象
	 * @param html
	 * @throws ErrorMessage
	 */
	public void put(Html html) throws ErrorMessage{
		this.frame.put(html);
	}
	
	/**
	 * 向Frame容器放入Html对象
	 * @param html
	 * @throws ErrorMessage
	 */
	public void putFrame(Html html) throws ErrorMessage{
		this.frame.putFrame(html);
	}

	/**
	 * 向Popup容器内放入Html对象
	 * @param html
	 * @throws ErrorMessage
	 */
	public void putPopup(Html html) throws ErrorMessage{
		this.prompt.put(html);
	}
	
	/**
	 * : 设置背景cssID
	 * @param cssID
	 */
	protected void setCssID(String cssID) {
		this.cssID = cssID;
	}
	
	private void bindBodyClickClose(HtmlWindow prompt) throws ErrorMessage{
		prompt.bind(Window_Event.OnClick, "fc('"+this.ID+"');");
	}
}
